﻿Namespace UserControls
    Public Class ActionUserControl

#Region "Form Event Handlers"
        Private Sub ActionUserControl_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ActionsComboBox.DataSource = NabaztagLib.Lookups.Actions.GetActionsBindingSource
            SerialNumberTextBox.Text = My.Settings.DefaultSerialNumber
            TokenTextBox.Text = My.Settings.DefaultToken
        End Sub
#End Region

#Region "Child Control Event Handlers"
        Private Sub SendButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SendButton.Click
            Dim message As NabazTagLib.Messages.IRequest = GetActionMessage()
            Dim response As String = NabaztagLib.MessageService.SendMessage(message).ToString
            ResponseTextBox.Text = response
        End Sub
#End Region

#Region "Methods"
        Private Function GetActionMessage() As NabaztagLib.Messages.ActionMessage
            Dim serialNumber As String = SerialNumberTextBox.Text
            Dim token As String = Int32.Parse(TokenTextBox.Text)
            Dim actionDescription As String = ActionsComboBox.SelectedValue
            Dim action As NabaztagLib.Lookups.ActionEnum = NabaztagLib.Lookups.Actions.GetActionEnumFromDescription(actionDescription)

            Dim message As New NabazTagLib.Messages.ActionMessage(serialNumber, token, action)
            Return message
        End Function
#End Region

    End Class
End Namespace
